// 缓存监控路由
import { Router } from 'express';
import cacheController from '@/controllers/monitor/cache.controller';
import { authMiddleware } from '@/middlewares/auth.middleware';
import { permissionMiddleware } from '@/middlewares/permission.middleware';

const router = Router();

/**
 * 缓存监控路由
 * 路径前缀：/monitor/cache
 */

// ================== 缓存监控相关 ==================

// 所有路由均需认证
router.use(authMiddleware);

// 获取Redis基本信息、dbSize、命令统计
router.get('/', permissionMiddleware('monitor:cache:list'), cacheController.getInfo);

// 获取常用缓存名称列表
router.get('/getNames', permissionMiddleware('monitor:cache:list'), cacheController.getNames);

// 获取指定缓存名下所有key
router.get('/getKeys/:cacheName', permissionMiddleware('monitor:cache:list'), cacheController.getKeys);

// 获取指定key的值
router.get('/getValue/:cacheName/:cacheKey', permissionMiddleware('monitor:cache:list'), cacheController.getValue);

// 清理指定缓存名下所有key
router.delete('/clearCacheName/:cacheName', permissionMiddleware('monitor:cache:list'), cacheController.clearCacheName);

// 清理指定key
router.delete('/clearCacheKey/:cacheKey', permissionMiddleware('monitor:cache:list'), cacheController.clearCacheKey);

// 清理所有缓存
router.delete('/clearCacheAll', permissionMiddleware('monitor:cache:list'), cacheController.clearCacheAll);

export default router; 